<%@ page language="java" contentType="text/html; charset=gb2312" pageEncoding="gb2312" session="true"%>
<%@ page import="beans.CommanderBean" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Shutdown a VM</title>
</head>
<body>
<%
	String loginCmd = (String)session.getAttribute("loginCmd");
	String VMName = request.getParameter("VMName");
	
	/***debug***/
	System.out.println("VMName is:"+VMName+"(in shutdownVM.jsp).");
	/***********/
	
	if(VMName==null||loginCmd==null) out.println("Error!");
	else{
			String part = "CLOSE VM:VMNAME=";
			String shutdownVMCmd = part+VMName;
			CommanderBean commander = new CommanderBean();
			String reply = commander.sendCommand(loginCmd);
			int pos = reply.indexOf('=')+1;
			if(reply.charAt(pos)=='0'){
					reply = commander.sendCommand(shutdownVMCmd);
					if(reply.charAt(reply.indexOf("=")+1)=='0'){
						commander.close();
%>
						<jsp:forward page="onSuccess.jsp"/> 	
<%  				} else {
							out.println("Failed to shutdown VM!");	%>
							<%--Add code later --%>
							<a href="listVMs.jsp">Go Back To the VM list</a>
							<a href="logout.jsp">Logout</a>
							<%-- --%>
<%					}
			} else {
				out.println("Failed to send shutdown command!");%>
				<a href="listVMs.jsp">Go Back To the VM list</a>
				<a href="logout.jsp">Logout</a>
<%			}
		}%>
</body>
</html>